package com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl;

import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SafeOperationBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.ISafeOperationDetailModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationDetailPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationDetailView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2017/7/13.
 */
public class SafeOperationDetailPresenter implements ISafeOperationDetailPresenter{
    private ISafeOperationDetailModel mModel;
    private ISafeOperationDetailView mView;

    public SafeOperationDetailPresenter(ISafeOperationDetailView view,ISafeOperationDetailModel model){
        mModel=model;
        mView=view;
    }


    @Override
    public void getSafeOperationDate(Map<String, String> praise) {
        mModel.getSafeOperationDate(praise)
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
//                        log.info("UserPresenter_doInLogin_SHOW_DIALOG");
                        mView.loadingDialogStatus(AppConfig.SHOW_DIALOG);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<SafeOperationBean>() {
                    @Override
                    public void onCompleted() {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.loadingDialogStatus(AppConfig.DISMISS_DIALOG);
                    }

                    @Override
                    public void onNext(SafeOperationBean safeOperationBean) {
                        mView.getSafeOperationDate(safeOperationBean);
                    }
                });
    }
}
